<template>
  <div :class="className" :id="id" :style="{height:height,width:width}" />
</template>

<script type="text/ecmascript-6">
import echarts from 'echarts'
import resize from './mixins/resize'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'linechart'
    },
    id: {
      type: String,
      default: 'linechart'
    },
    width: {
      type: String,
      default: '200px'
    },
    height: {
      type: String,
      default: '200px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initChart()
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(document.getElementById(this.id))

      this.chart.setOption({
        grid: {
          top: 5,
          left: 0,
          right: 0,
          bottom: '30',
          containLabel: true
        },
        series: [{
          name: '支付订单的实际支付金额的总和',
          type: 'line',
          symbol: 'circle',
          symbolSize: 8,
          lineStyle: {
            color: '#55acee',
            width: 1
          },
          itemStyle: {
            color: '#55acee'
          },
          data: [136, 138, 129, 141, 147, 141, 143]
        }],
        xAxis: [{
          type: 'category',
          axisLine: {
            lineStyle: {
              color: '#cccccc'
            }
          },
          axisLabel: {
            color: '#8492a6'
          },
          axisTick: {
            alignWithLabel: true
          },
          data: ['10-29', '10-30', '10-31', '11-1', '11-2', '11-3', '11-4']

        }],
        yAxis: [{
          type: 'value',
          min: 125,
          axisLine: {
            show: false,
            lineStyle: {
              color: '#8492a6'
            }
          },
          axisLabel: {
            margin: 10,
            formatter: '{value} 万',
            textStyle: {
              fontSize: 12
            }
          },
          axisTick: {
            show: false
          },
          splitLine: {
            lineStyle: {
              type: 'dotted',
              color: '#d8d8d8'
            }
          }
        }],
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            lineStyle: {
              color: '#d8d8d8'
            }
          },
          textStyle: {
            fontSize: 12
          }
        },
        legend: {
          type: 'plain',
          bottom: 0,
          icon: 'rect',
          itemWidth: 20,
          itemHeight: 3,
          itemGap: 5,
          zlevel: 10,
          data: ['支付订单的实际支付金额的总和'],
          textStyle: {
            fontSize: 12,
            color: '#8492a6'
          }
        }

      })
    }
  }
}
</script>

<style lang="stylus" scoped>
</style>
